package palmtop.com.palmtop.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Poi;
import com.amap.api.navi.AmapNaviPage;
import com.amap.api.navi.AmapNaviParams;
import com.amap.api.navi.AmapNaviType;
import com.amap.api.navi.INaviInfoCallback;
import com.amap.api.navi.model.AMapNaviLocation;
import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.beardedhen.androidbootstrap.BootstrapButton;

import java.util.ArrayList;

import palmtop.com.palmtop.R;
import palmtop.com.palmtop.activity.DisleadertaskActivity;
import palmtop.com.palmtop.activity.DotaskActivity;
import palmtop.com.palmtop.activity.MytaskdetailActivity;
import palmtop.com.palmtop.activity.ProcesstaskActivity;
import palmtop.com.palmtop.activity.TaskdetailActivity;
import palmtop.com.palmtop.model.Taskgrid;

/**
 * Created by Administrator on 2017/9/1.
 */

public class WaitTaskAdapter extends BaseAdapter {
    private ArrayList<Taskgrid> arrlist;
    private Context context;

    public WaitTaskAdapter(ArrayList<Taskgrid> arrlist, Context context) {
        this.arrlist = arrlist;
        this.context = context;
    }

    @Override
    public int getCount() {
        return arrlist.size();
    }

    @Override
    public Object getItem(int i) {
        return arrlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int pos, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_waittask,null);
        AwesomeTextView taskname = view.findViewById(R.id.taskname);
        //AwesomeTextView status = view.findViewById(R.id.status);
        AwesomeTextView taskaddress = view.findViewById(R.id.taskaddress);
        AwesomeTextView adddate = view.findViewById(R.id.adddate);

        final Taskgrid taskgrid = arrlist.get(pos);
        if(taskgrid.getTaskname().equals("")){
            taskname.setText(" ");
        }else{
            taskname.setText(taskgrid.getTaskname());
        }
        if(taskgrid.getAdddate().equals("")){
            adddate.setText(" ");
        }else{
            adddate.setText(taskgrid.getAdddate());
        }
        if(taskgrid.getTaskaddress().equals("")){
            taskaddress.setText(" ");
        }else{
            taskaddress.setText(taskgrid.getTaskaddress());
        }
//        taskaddress.setText(taskgrid.getTaskaddress());

        Button xiafa = view.findViewById(R.id.xiafa);
        Button daohang = view.findViewById(R.id.daohang);
        Button xiangqing = view.findViewById(R.id.xiangqing);
        Button zhixing = view.findViewById(R.id.zhixing);

        zhixing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent();
                i.putExtra("taskgrid",taskgrid);
                i.setClass(context, DotaskActivity.class);
                context.startActivity(i);
            }
        });

            //下发
            xiafa.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //社区民警下发任务
                    Intent i = new Intent();
                    i.putExtra("taskgrid",taskgrid);
                    i.setClass(context, DisleadertaskActivity.class);
                    context.startActivity(i);

                }
            });



        //导航
        daohang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Poi end = new Poi("", new LatLng(Double.valueOf(taskgrid.getLatitude()), Double.valueOf(taskgrid.getLongitude())),"");
                AmapNaviParams mAmapNaviParams = new AmapNaviParams(null,null,end, AmapNaviType.DRIVER);
                mAmapNaviParams.setUseInnerVoice(true);
                AmapNaviPage.getInstance().showRouteActivity(context, mAmapNaviParams, new INaviInfoCallback() {
                    @Override
                    public void onInitNaviFailure() {

                    }

                    @Override
                    public void onGetNavigationText(String s) {

                    }

                    @Override
                    public void onLocationChange(AMapNaviLocation aMapNaviLocation) {

                    }

                    @Override
                    public void onArriveDestination(boolean b) {

                    }

                    @Override
                    public void onStartNavi(int i) {

                    }

                    @Override
                    public void onCalculateRouteSuccess(int[] ints) {

                    }

                    @Override
                    public void onCalculateRouteFailure(int i) {

                    }

                    @Override
                    public void onStopSpeaking() {

                    }

                    @Override
                    public void onReCalculateRoute(int i) {

                    }

                    @Override
                    public void onExitPage(int i) {

                    }

                    @Override
                    public void onStrategyChanged(int i) {

                    }

                    @Override
                    public View getCustomNaviBottomView() {
                        return null;
                    }

                    @Override
                    public View getCustomNaviView() {
                        return null;
                    }

                    @Override
                    public void onArrivedWayPoint(int i) {

                    }
                });

            }
        });
        //详情
        xiangqing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent();
                i.putExtra("taskgrid",taskgrid);
                i.setClass(context, TaskdetailActivity.class);
                context.startActivity(i);
            }
        });

        return view;
    }
}
